﻿using System.Collections.Generic;
using SystemModule;

namespace M2Server
{
    public partial class TPlayObject
    {
        /// <summary>
        /// 初始化消息处理进程
        /// RM：客户端
        /// CM: 服务端
        /// </summary>
        private void InitProcessMessageList()
        {
            FServerProcess = new Dictionary<int, TServerProcess>();
            FServerProcess[Grobal2.RM_LOGON] = ServerLogon;
            FServerProcess[Grobal2.CM_WALK] = ClientWalk;
            FServerProcess[Grobal2.CM_TURN] = ClientTurn;
            FServerProcess[Grobal2.CM_RUN] = ClientRun;
            FServerProcess[Grobal2.RM_STRUCK] = ServerStruck;
            FServerProcess[Grobal2.RM_STRUCK_MAG] = ServerStruck;
            FServerProcess[Grobal2.CM_HIT] = ClientAttack;
            FServerProcess[Grobal2.CM_HEAVYHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_BIGHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_POWERHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_LONGHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_WIDEHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_CRSHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_TWNHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_QTWINHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_CIDHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_PHHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_DAILY] = ClientAttack;
            FServerProcess[Grobal2.CM_FIREHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_4FIREHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_SANJUEHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_ZHUIXINHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_DUANYUEHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_HENGSAOHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_YTPDHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_XPYJHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_4LONGHIT] = ClientAttack;
            FServerProcess[Grobal2.CM_YUANYUEHIT] = ClientAttack;
            FServerProcess[Grobal2.RM_CHANGETURN] = ServerTurn;
            FServerProcess[Grobal2.RM_TURN] = ServerTurn;
            FServerProcess[Grobal2.RM_PUSH] = ServerTurn;
            FServerProcess[Grobal2.RM_RUSH] = ServerTurn;
            FServerProcess[Grobal2.RM_PUSHEX] = ServerTurn;
            FServerProcess[Grobal2.RM_RUSHKUNG] = ServerTurn;
            FServerProcess[Grobal2.RM_HEAR] = ServerSay;
            FServerProcess[Grobal2.RM_WHISPER] = ServerSay;
            FServerProcess[Grobal2.RM_CRY] = ServerSay;
            FServerProcess[Grobal2.RM_SYSMESSAGE] = ServerSay;
            FServerProcess[Grobal2.RM_MOVEMESSAGE] = ServerSay;
            FServerProcess[Grobal2.RM_GROUPMESSAGE] = ServerSay;
            FServerProcess[Grobal2.RM_SYSMESSAGE2] = ServerSay;
            FServerProcess[Grobal2.RM_GUILDMESSAGE] = ServerSay;
            FServerProcess[Grobal2.RM_SYSMESSAGE3] = ServerSay;
            FServerProcess[Grobal2.RM_PLAYDRINKSAY] = ServerSay;
            FServerProcess[Grobal2.RM_MERCHANTSAY] = ServerSay;// 滚动公告
            FServerProcess[Grobal2.RM_CHANGEMAP] = ServerChangeMap;
            FServerProcess[Grobal2.CM_SPELL] = ClientSpell;
            FServerProcess[Grobal2.RM_SPACEMOVE_SHOW] = ServerSpaceMoveShow;
            FServerProcess[Grobal2.RM_SPACEMOVE_SHOW2] = ServerSpaceMoveShow;
            FServerProcess[Grobal2.CM_BUTCH] = ClientButch;
            FServerProcess[Grobal2.CM_HORSERUN] = ClientHorseRun;
            FServerProcess[Grobal2.CM_SITDOWN] = ClientSitDown;
            FServerProcess[Grobal2.RM_WALK] = ServerWalk;
            FServerProcess[Grobal2.RM_HORSERUN] = ServerHorseRun;
            FServerProcess[Grobal2.RM_RUN] = ServerRun;
            FServerProcess[Grobal2.RM_LEVELUP] = ServerLevelUp;
            FServerProcess[Grobal2.RM_ABILITY] = ServerAbilty;

            FServerProcess[Grobal2.RM_SPELL] = ServerSpell;
            FServerProcess[Grobal2.RM_DEATH] = ServerDeath;
            FServerProcess[Grobal2.RM_BUTCH] = ServerButch;
            FServerProcess[Grobal2.RM_DIGUP] = ServerDigUp;
            FServerProcess[Grobal2.RM_FLYAXE] = ServerFlyAxe;
            FServerProcess[Grobal2.RM_LIGHTING] = ServerLighting;
            FServerProcess[Grobal2.RM_FAIRYATTACKRATE] = ServerFairyattackrate;
            FServerProcess[Grobal2.RM_SHOWEVENT] = ServerShowEvent;
            FServerProcess[Grobal2.RM_DAYCHANGING] = ServerDayChanging;
            FServerProcess[Grobal2.RM_NPCWALK] = ServerNpcWalk;
            FServerProcess[Grobal2.RM_ALIVE] = ServerAlive;
            FServerProcess[Grobal2.RM_CHANGEFACE] = ServerChangFace;
            FServerProcess[Grobal2.RM_PLAYDICE] = ServerPlayDice;
        }

        private void ServerPlayDice(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TMessageBodyWL MessageBodyWL = new TMessageBodyWL();
            MessageBodyWL.lParam1 = ProcessMsg.nParam1;
            MessageBodyWL.lParam2 = ProcessMsg.nParam2;
            MessageBodyWL.lTag1 = ProcessMsg.nParam3;
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_PLAYDICE, ProcessMsg.BaseObject, ProcessMsg.wParam, 0, 0, 0);
            SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(MessageBodyWL) + EncryptUnit.EncodeString(ProcessMsg.sMsg));
        }

        private void ServerChangFace(TProcessMessage ProcessMsg, ref bool boResult)
        {
            if ((ProcessMsg.nParam1 != 0) && (ProcessMsg.nParam2 != 0))
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CHANGEFACE, ProcessMsg.nParam1, HUtil32.LoWord(ProcessMsg.nParam2), HUtil32.HiWord(ProcessMsg.nParam2), 0, 0);
                TCharDesc CharDesc = new TCharDesc();
                var objobject = M2Share.ActorsSystem.Get(ProcessMsg.nParam2);
                CharDesc.feature = objobject.GetFeature(this);
                CharDesc.Status = objobject.m_nCharStatus;
                CharDesc.Opature = objobject.GetFeatureJob();
                CharDesc.Level = objobject.m_WAbil.Level;         //20191229
                CharDesc.HP = objobject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = objobject.m_WAbil.MaxHP;         //20191229
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
            }
        }

        /// <summary>
        /// 复活
        /// </summary>
        private void ServerAlive(TProcessMessage ProcessMsg, ref bool boResult)
        {
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_ALIVE, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
            TCharDesc CharDesc = new TCharDesc();
            var objobject = M2Share.ActorsSystem.Get(ProcessMsg.nParam2);
            CharDesc.feature = objobject.GetFeature(this);
            CharDesc.Status = objobject.m_nCharStatus;
            CharDesc.Opature = objobject.GetFeatureJob();
            CharDesc.Level = objobject.m_WAbil.Level;         //20191229
            CharDesc.HP = objobject.m_WAbil.HP;               //20191229
            CharDesc.MaxHP = objobject.m_WAbil.MaxHP;         //20191229
            SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
        }

        /// <summary>
        /// 酿酒NPC移动
        /// </summary>
        private void ServerNpcWalk(TProcessMessage ProcessMsg, ref bool boResult)
        {
            if (M2Share.ActorsSystem.Get(ProcessMsg.BaseObject) != this)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_NPCWALK, ProcessMsg.BaseObject, ProcessMsg.nParam1,
                    ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam, M2Share.ActorsSystem.Get(ProcessMsg.BaseObject).m_btJob), 0);
                TCharDesc CharDesc = new TCharDesc();
                var objobject = M2Share.ActorsSystem.Get(ProcessMsg.nParam2);
                CharDesc.feature = objobject.GetFeature(objobject);
                CharDesc.Status = objobject.m_nCharStatus;
                CharDesc.Opature = objobject.GetFeatureJob();
                CharDesc.Level = objobject.m_WAbil.Level;         //20191229
                CharDesc.HP = objobject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = objobject.m_WAbil.MaxHP;         //20191229
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
            }
        }

        private void ServerDayChanging(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nObjCount = -1;
            if (this.m_PEnvir.m_boDARK)
            {
                nObjCount = 1;
            }
            else
            {
                switch (m_nBright)
                {
                    case 1:
                        nObjCount = 0;
                        break;
                    case 3:
                        nObjCount = 1;
                        break;
                    default:
                        nObjCount = 1;
                        break;
                }
            }
            if (this.m_PEnvir.m_boDAY)
            {
                nObjCount = 0;
            }
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_DAYCHANGING, 0, m_nBright, nObjCount, 0, 0);
            SendSocket(this.m_DefMsg, "");
        }

        /// <summary>
        /// 显示地图事件
        /// </summary>
        private void ServerShowEvent(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TShortMessage ShortMessage = new TShortMessage();
            ShortMessage.Ident = (ushort)HUtil32.HiWord(ProcessMsg.nParam2);
            ShortMessage.wMsg = 0;
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SHOWEVENT, ProcessMsg.nParam1, ProcessMsg.wParam,
                ProcessMsg.nParam2, ProcessMsg.nParam3, 0);
            unsafe
            {
                byte[] data = new byte[sizeof(TShortMessage)];
                fixed (byte* pb = data)
                {
                    *(TShortMessage*)pb = ShortMessage;
                    SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(data, sizeof(TShortMessage)));
                }
            }
        }

        private unsafe void ServerFairyattackrate(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.nParam3);
            if (BaseObject != null)
            {
                TMessageBodyWL MessageBodyWL = new TMessageBodyWL();
                MessageBodyWL.lParam1 = BaseObject.m_nCurrX;
                MessageBodyWL.lParam2 = BaseObject.m_nCurrY;
                MessageBodyWL.lTag1 = ProcessMsg.nParam3;
                MessageBodyWL.lTag2 = ProcessMsg.wParam;
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_FAIRYATTACKRATE, ProcessMsg.BaseObject, ProcessMsg.nParam1,
                    ProcessMsg.nParam2, M2Share.ActorsSystem.Get(ProcessMsg.BaseObject).m_btDirection, 0);
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(MessageBodyWL));
            }
        }

        private unsafe void ServerLighting(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.nParam3);
            if (BaseObject != null)
            {
                TMessageBodyWL MessageBodyWL = new TMessageBodyWL();
                MessageBodyWL.lParam1 = BaseObject.m_nCurrX;
                MessageBodyWL.lParam2 = BaseObject.m_nCurrY;
                MessageBodyWL.lTag1 = ProcessMsg.nParam3;
                MessageBodyWL.lTag2 = ProcessMsg.wParam;
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_LIGHTING, ProcessMsg.BaseObject, ProcessMsg.nParam1,
                    ProcessMsg.nParam2, M2Share.ActorsSystem.Get(ProcessMsg.BaseObject).m_btDirection, 0);
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(MessageBodyWL));
            }
        }

        private unsafe void ServerFlyAxe(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.nParam3);
            if (BaseObject != null)
            {
                TMessageBodyW MessageBodyW = new TMessageBodyW();
                MessageBodyW.Param1 = (ushort)BaseObject.m_nCurrX;
                MessageBodyW.Param2 = (ushort)BaseObject.m_nCurrY;
                MessageBodyW.Tag1 = (ushort)HUtil32.LoWord(ProcessMsg.nParam3);
                MessageBodyW.Tag2 = (ushort)HUtil32.HiWord(ProcessMsg.nParam3);
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_FLYAXE, ProcessMsg.BaseObject, ProcessMsg.nParam1,
                    ProcessMsg.nParam2, ProcessMsg.wParam, 0);
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(MessageBodyW));
            }
        }

        private unsafe void ServerDigUp(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_DIGUP, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                (byte)M2Share.ActorsSystem.Get(ProcessMsg.BaseObject).m_nLight), 0);
            TMessageBodyWL MessageBodyWL = new TMessageBodyWL();
            MessageBodyWL.lParam1 = BaseObject.GetFeature(this);
            MessageBodyWL.lParam2 = BaseObject.m_nCharStatus;
            MessageBodyWL.lTag1 = ProcessMsg.nParam3;
            MessageBodyWL.lTag1 = 0;
            string s1C = EncryptUnit.EncodeBuffer(MessageBodyWL);
            SendSocket(this.m_DefMsg, s1C);
        }

        /// <summary>
        /// 发送解包物品数据
        /// </summary>
        /// <param name="ProcessMsg"></param>
        /// <param name="boResult"></param>
        private void ServerButch(TProcessMessage ProcessMsg, ref bool boResult)
        {
            if (ProcessMsg.BaseObject != 0)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_BUTCH, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
                SendSocket(this.m_DefMsg, "");
            }
        }

        private void ServerDeath(TProcessMessage ProcessMsg, ref bool boResult)
        {
            if (ProcessMsg.nParam3 == 1)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_NOWDEATH, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
            }
            else
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_DEATH, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
            }
            TCharDesc CharDesc = new TCharDesc();
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            CharDesc.feature = BaseObject.GetFeature(this);
            CharDesc.Status = BaseObject.m_nCharStatus;

            CharDesc.Opature = BaseObject.GetFeatureJob();
            CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
            CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
            CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229
            SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
        }

        private void ServerSpell(TProcessMessage ProcessMsg, ref bool boResult)
        {
            if (M2Share.ActorsSystem.Get(ProcessMsg.BaseObject) != this)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SPELL, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
                SendSocket(this.m_DefMsg, (ProcessMsg.nParam3).ToString());
            }
            else
            {
                if (HUtil32.rangeInDefined(ProcessMsg.nParam3, 60, 65) || HUtil32.rangeInDefined(ProcessMsg.nParam3, 76, 87))
                {
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SPELL, ProcessMsg.BaseObject,
                  ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, 0);
                    SendSocket(this.m_DefMsg, (ProcessMsg.nParam3).ToString());
                }
            }
        }

        /// <summary>
        /// 玩家熟悉
        /// </summary>
        private void ServerAbilty(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TOAbility OAbility = null;
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_ABILITY, this.m_nGold, HUtil32.MakeWord(this.m_btJob, 99), HUtil32.LoWord(m_nGameGold), HUtil32.HiWord(m_nGameGold), 0);
            if ((m_nSoftVersionDateEx == 0) && (m_dwClientTick == 0))
            {
                GetOldAbil(OAbility);
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(OAbility));
                if (M2Share.g_Config.boOldClientShowHiLevel && (this.m_Abil.Level > 255))// '由于您使用的客户端版本太老了，无法正确显示人物信息！！！'
                {
                    this.SysMsg(GameMsgDef.g_sClientVersionTooOld, TMsgColor.c_Red, TMsgType.t_Hint);
                    this.SysMsg("当前等级: " + this.m_Abil.Level, TMsgColor.c_Green, TMsgType.t_Hint);
                    this.SysMsg("当前生命值: " + this.m_WAbil.HP + "-" + this.m_WAbil.MaxHP, TMsgColor.c_Blue, TMsgType.t_Hint);
                    this.SysMsg("当前魔法值: " + this.m_WAbil.MP + "-" + this.m_WAbil.MaxMP, TMsgColor.c_Red, TMsgType.t_Hint);
                    this.SysMsg("当前防御力: " + HUtil32.LoWord(this.m_WAbil.AC) + "-" + HUtil32.HiWord(this.m_WAbil.AC), TMsgColor.c_Green, TMsgType.t_Hint);
                    this.SysMsg("当前魔防力: " + HUtil32.LoWord(this.m_WAbil.MAC) + "-" + HUtil32.HiWord(this.m_WAbil.MAC), TMsgColor.c_Blue, TMsgType.t_Hint);
                    this.SysMsg("当前攻击力: " + HUtil32.LoWord(this.m_WAbil.DC) + "-" + HUtil32.HiWord(this.m_WAbil.DC), TMsgColor.c_Red, TMsgType.t_Hint);
                    this.SysMsg("当前魔法力: " + HUtil32.LoWord(this.m_WAbil.MC) + "-" + HUtil32.HiWord(this.m_WAbil.MC), TMsgColor.c_Green, TMsgType.t_Hint);
                    this.SysMsg("当前道术值: " + HUtil32.LoWord(this.m_WAbil.SC) + "-" + HUtil32.HiWord(this.m_WAbil.SC), TMsgColor.c_Blue, TMsgType.t_Hint);
                }
            }
            else
            {
                var sSendMsg = EncryptUnit.EncodeBuffer(this.m_WAbil);
                SendSocket(this.m_DefMsg, sSendMsg);
            }
            System.Console.WriteLine("123");
            //m_DefMsg := MakeDefaultMsg(SM_ABILITY2, 0, 0, 0, 0, 0); //发送元素
            //SendSocket(@m_DefMsg, EncodeBuffer(@m_NewWAbil, SizeOf(TNewAbility)));
        }

        /// <summary>
        /// 玩家升级
        /// </summary>
        private void ServerLevelUp(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TOAbility OAbility = null;
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_LEVELUP, this.m_Abil.Exp, this.m_Abil.Level, 0, 0, 0);
            SendSocket(this.m_DefMsg, "");
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_ABILITY, this.m_nGold, HUtil32.MakeWord(this.m_btJob, 99), HUtil32.LoWord(m_nGameGold),
                HUtil32.HiWord(m_nGameGold), 0);// 0806 增加
            if ((m_nSoftVersionDateEx == 0) && (m_dwClientTick == 0))
            {
                GetOldAbil(OAbility);
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(OAbility));
            }
            else
            {
                var sSendMsg = EncryptUnit.EncodeBuffer(this.m_WAbil);
                SendSocket(this.m_DefMsg, sSendMsg);
            }
            SendDefMessage(Grobal2.SM_SUBABILITY, HUtil32.MakeLong(HUtil32.MakeWord((byte)this.m_nAntiMagic, 0), 0), HUtil32.MakeWord(this.m_btHitPoint, this.m_btSpeedPoint),
                HUtil32.MakeWord((byte)this.m_btAntiPoison, (byte)this.m_nPoisonRecover), HUtil32.MakeWord((byte)this.m_nHealthRecover, (byte)this.m_nSpellRecover), "");
        }

        private void ServerRun(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            if (BaseObject != this)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_RUN, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                    (byte)BaseObject.m_nLight), 0);
                TCharDesc CharDesc = new TCharDesc();
                CharDesc.feature = BaseObject.GetFeature(BaseObject);
                CharDesc.Status = BaseObject.m_nCharStatus;
                CharDesc.Opature = BaseObject.GetFeatureJob();
                CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
                CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229
                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
            }
        }

        private void ServerHorseRun(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            if (BaseObject != this)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_HORSERUN, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                    (byte)BaseObject.m_nLight), 0);
                TCharDesc CharDesc = new TCharDesc();
                CharDesc.feature = BaseObject.GetFeature(BaseObject);
                CharDesc.Status = BaseObject.m_nCharStatus;

                CharDesc.Opature = BaseObject.GetFeatureJob();
                CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
                CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229

                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
            }
        }

        private void ServerWalk(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            if (BaseObject != this)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_WALK, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                    (byte)BaseObject.m_btJob), 0);
                TCharDesc CharDesc = new TCharDesc();
                CharDesc.feature = BaseObject.GetFeature(BaseObject);
                CharDesc.Status = BaseObject.m_nCharStatus;

                CharDesc.Opature = BaseObject.GetFeatureJob();
                CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
                CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229

                SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(CharDesc));
            }
        }

        /// <summary>
        /// 蹲下？
        /// </summary>
        private unsafe void ClientSitDown(TProcessMessage ProcessMsg, ref bool boResult)
        {
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientSitDownHit(ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                SendSocket(null, M2Share.sSTATUS_GOOD);
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetSiteDownMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxSitDonwMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                // '请勿使用非法软件！！！'
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sBunOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        // 如果超速则发送攻击失败信息
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                    }
                    else
                    {
                        if (dwDelayTime < M2Share.g_Config.dwDropOverSpeed)
                        {
                            SendSocket(null, M2Share.sSTATUS_GOOD);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("操作延迟 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }

        }

        /// <summary>
        /// 骑马攻击
        /// </summary>
        private unsafe void ClientHorseRun(TProcessMessage ProcessMsg, ref bool boResult)
        {
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientHorseRunXY(ProcessMsg.wIdent, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.boLateDelivery, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetRunMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxRunMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint); // '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sRunOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        // 如果超速则发送攻击失败信息
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                        if (m_boTestSpeedMode)
                        {
                            this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                        }
                    }
                    else
                    {
                        if (m_boTestSpeedMode)
                        {
                            this.SysMsg(string.Format("操作延迟 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                        }
                        this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                        boResult = false;
                    }
                }
            }
        }

        /// <summary>
        /// 挖取物品
        /// </summary>
        private unsafe void ClientButch(TProcessMessage ProcessMsg, ref bool boResult)
        {
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (!ClientGetButchItem(M2Share.ActorsSystem.Get(ProcessMsg.nParam1), ProcessMsg.nParam2, ProcessMsg.nParam3, (byte)ProcessMsg.wParam, ref dwDelayTime))
            {
                if (dwDelayTime != 0)
                {
                    nMsgCount = GetDigUpMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxDigUpMsgCount)// 越过M2的挖肉限制数量
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint); // '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sBunOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        SendSocket(null, M2Share.sSTATUS_FAIL);// 如果超速则发送攻击失败信息
                    }
                    else
                    {
                        if (dwDelayTime < M2Share.g_Config.dwDropOverSpeed)
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            SendSocket(null, M2Share.sSTATUS_GOOD);
                        }
                        else
                        {
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 移动？
        /// </summary>
        private void ServerSpaceMoveShow(TProcessMessage ProcessMsg, ref bool boResult)
        {
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            if (ProcessMsg.wIdent == Grobal2.RM_SPACEMOVE_SHOW)
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SPACEMOVE_SHOW, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2,
                    HUtil32.MakeWord((byte)ProcessMsg.wParam, (byte)BaseObject.m_nLight), 0);
            }
            else
            {
                this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SPACEMOVE_SHOW2, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2,
                    HUtil32.MakeWord((byte)ProcessMsg.wParam, (byte)BaseObject.m_nLight), 0);
            }
            TCharDesc CharDesc = new TCharDesc();
            CharDesc.feature = BaseObject.GetFeature(this);
            CharDesc.Status = BaseObject.m_nCharStatus;

            CharDesc.Opature = BaseObject.GetFeatureJob();
            CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
            CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
            CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229

            string s1C = EncryptUnit.EncodeBuffer(CharDesc);

            int nObjCount = this.GetCharColor(BaseObject);
            if (ProcessMsg.sMsg != null && ProcessMsg.sMsg != "")
            {
                s1C = s1C + EncryptUnit.EncodeString(ProcessMsg.sMsg + "/" + (nObjCount).ToString());
            }
            SendSocket(this.m_DefMsg, s1C);
        }

        /// <summary>
        /// 使用技能
        /// </summary>
        private unsafe void ClientSpell(TProcessMessage ProcessMsg, ref bool boResult)
        {
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientSpellXY((ushort)ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2,
                M2Share.ActorsSystem.Get(ProcessMsg.nParam3), ProcessMsg.boLateDelivery, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetSpellMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxSpellMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint); // '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage) // 如果超速则发送攻击失败信息
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sSpellOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                    }
                    else
                    {
                        if ((dwDelayTime > M2Share.g_Config.dwDropOverSpeed) && (M2Share.g_Config.btSpeedControlMode == 1) && m_boFilterAction)
                        {
                            SendSocket(null, M2Share.sSTATUS_FAIL);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("操作延迟 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 切换地图
        /// </summary>
        private void ServerChangeMap(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nObjCount = -1;
            if (this.m_PEnvir.m_boDARK)
            {
                nObjCount = 1;
            }
            else
            {
                switch (m_nBright)
                {
                    case 1:
                        nObjCount = 0;
                        break;
                    case 3:
                        nObjCount = 1;
                        break;
                    default:
                        nObjCount = 1;
                        break;
                }
            }
            if (this.m_PEnvir.m_boDAY)
            {
                nObjCount = 0;
            }
            SendDefMessage(Grobal2.SM_CHANGEMAP, this.m_ActorsId, this.m_nCurrX, this.m_nCurrY, nObjCount, ProcessMsg.sMsg);
            RefUserState();
            SendMapDescription();
            SendServerConfig();// 发送服务端配置
            SendUnBind();
        }

        /// <summary>
        /// 登录游戏
        /// </summary>
        private void ServerLogon(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nObjCount = -1;
            if (this.m_PEnvir.m_boDARK)
            {
                nObjCount = 1;
            }
            else
            {
                switch (m_nBright)
                {
                    case 1:
                        nObjCount = 0;
                        break;
                    case 3:
                        nObjCount = 1;
                        break;
                    default:
                        nObjCount = 1;
                        break;
                }
            }
            if (this.m_PEnvir.m_boDAY)
            {
                nObjCount = 0;
            }
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_NEWMAP, this.m_ActorsId, this.m_nCurrX, this.m_nCurrY, nObjCount, 0);
            SendSocket(this.m_DefMsg, EncryptUnit.EncodeString(M2Share.g_MapManager.GetMainMap(this.m_PEnvir)));
            this.SendMsg(this, Grobal2.RM_CHANGELIGHT, 0, 0, 0, 0, "");
            SendLogon();
            SendServerConfig();//发送服务器配置文件（比如穿怪 穿人等）
            SendUnBind();// 发送解包文件
            ClientQueryUserName(this, this.m_nCurrX, this.m_nCurrY);
            RefUserState();// 地图状态
            SendMapDescription();
            SendGoldInfo(true);
            SendGloryInfo();
            this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_VERSION_FAIL, M2Share.g_Config.nClientFile1_CRC, 0, 0, 0, 0);// 验证客户端版本 
            SendSocket(this.m_DefMsg, "");
        }

        /// <summary>
        /// 系统公告
        /// </summary>
        private void ServerSay(TProcessMessage ProcessMsg, ref bool boResult)
        {
            switch (ProcessMsg.wIdent)
            {
                case Grobal2.RM_HEAR:
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_HEAR, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_WHISPER:// 10030
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_WHISPER, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_CRY:// 10031
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_CRY, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_SYSMESSAGE:// 10032
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SYSMESSAGE, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_MOVEMESSAGE:// 10100 红色 消息分类
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_MOVEMESSAGE, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1,
                        (byte)ProcessMsg.nParam2), ProcessMsg.nParam3, ProcessMsg.wParam, 0);
                    break;
                case Grobal2.RM_GROUPMESSAGE:// 10100 红色  
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_SYSMESSAGE, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_GUILDMESSAGE://10102
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_GUILDMESSAGE, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_MERCHANTSAY://10104 行会聊天
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_MERCHANTSAY, ProcessMsg.BaseObject, HUtil32.MakeWord((byte)ProcessMsg.nParam1, (byte)ProcessMsg.nParam2), 0, 1, 0);
                    break;
                case Grobal2.RM_PLAYDRINKSAY://10126
                    this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_PLAYDRINKSAY, ProcessMsg.BaseObject, ProcessMsg.nParam3, 0, 1, 0);
                    break;
            }
            SendSocket(this.m_DefMsg, EncryptUnit.EncodeString(ProcessMsg.sMsg));
        }

        /// <summary>
        ///  英雄转身 人物转身
        /// </summary>
        private void ServerTurn(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nCode = 152;
            TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
            if (((BaseObject != this) || (ProcessMsg.wIdent == Grobal2.RM_PUSH) ||
                (ProcessMsg.wIdent == Grobal2.RM_RUSH) || (ProcessMsg.wIdent == Grobal2.RM_RUSHKUNG) || (ProcessMsg.wIdent == Grobal2.RM_CHANGETURN)))
            {
                switch (ProcessMsg.wIdent)
                {
                    case Grobal2.RM_PUSH:
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_BACKSTEP, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                            (byte)BaseObject.m_nLight), 0);
                        break;
                    case Grobal2.RM_PUSHEX:
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_BATTERBACKSTEP, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                            (byte)BaseObject.m_nLight), 0);
                        break;
                    case Grobal2.RM_RUSH:
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_RUSH, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                            (byte)BaseObject.m_nLight), 0);
                        break;
                    case Grobal2.RM_RUSHKUNG:// 攻杀
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_RUSHKUNG, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                            (byte)BaseObject.m_nLight), 0);
                        break;
                    default://这里发送消息给客户端绘制NPC
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_TURN, ProcessMsg.BaseObject, ProcessMsg.nParam1, ProcessMsg.nParam2, HUtil32.MakeWord((byte)ProcessMsg.wParam,
                            (byte)BaseObject.m_nLight), 0);
                        break;
                }
                TCharDesc CharDesc = new TCharDesc();
                CharDesc.feature = BaseObject.GetFeature(BaseObject);
                CharDesc.Status = BaseObject.m_nCharStatus;

                CharDesc.Opature = BaseObject.GetFeatureJob();
                CharDesc.Level = BaseObject.m_WAbil.Level;         //20191229
                CharDesc.HP = BaseObject.m_WAbil.HP;               //20191229
                CharDesc.MaxHP = BaseObject.m_WAbil.MaxHP;         //20191229

                string s1C = EncryptUnit.EncodeBuffer(CharDesc);
                int nObjCount = this.GetCharColor(BaseObject);// 取人物名字颜色
                if (ProcessMsg.sMsg != null && ProcessMsg.sMsg != "")
                {
                    s1C = s1C + EncryptUnit.EncodeString(ProcessMsg.sMsg + "/" + nObjCount);
                }
                SendSocket(this.m_DefMsg, s1C);
                if (ProcessMsg.wIdent == Grobal2.RM_TURN)
                {
                    nObjCount = BaseObject.GetFeatureToLong();
                    SendDefMessage(Grobal2.SM_FEATURECHANGED, ProcessMsg.BaseObject, HUtil32.LoWord(nObjCount), HUtil32.HiWord(nObjCount), BaseObject.GetFeatureEx(), "");
                }
            }
        }

        /// <summary>
        /// 攻击目标
        /// </summary>
        private unsafe void ClientAttack(TProcessMessage ProcessMsg, ref bool boResult)
        {
            // 开天斩重击// 开天斩轻击// 龙影剑法// 逐日剑法// 烈火// 4级烈火
            // 三绝杀// 追心刺// 断岳斩// 横扫千军// 倚天劈地// 血魄一击// 4级刺杀// 圆月弯刀
            int nCode = 124;
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientHitXY(ProcessMsg.wIdent, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, ProcessMsg.boLateDelivery, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetHitMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxHitMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                // '请勿使用非法软件！！！'
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sHitOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        // 如果超速则发送攻击失败信息
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                    }
                    else
                    {
                        if ((dwDelayTime > M2Share.g_Config.dwDropOverSpeed) && (M2Share.g_Config.btSpeedControlMode == 1) && m_boFilterAction)
                        {
                            SendSocket(null, M2Share.sSTATUS_GOOD);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg("操作延迟 Ident: " + ProcessMsg.wIdent + " Time: " + dwDelayTime, TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        private unsafe void ClientRun(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nCode = 123;
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientRunXY(ProcessMsg.wIdent, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                if (M2Share.g_Config.boStartMapEvent)
                {
                    if (this.m_btRaceServer == Grobal2.RC_PLAYOBJECT)
                    {
                        StartMapEventOfRun(); // 跑步事件触发
                    }
                }
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetRunMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxRunMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint);// '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sRunOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        // 如果超速则发送攻击失败信息
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                    }
                    else
                    {
                        if ((dwDelayTime > M2Share.g_Config.dwDropOverSpeed) && (M2Share.g_Config.btSpeedControlMode == 1) && m_boFilterAction)
                        {
                            SendSocket(null, M2Share.sSTATUS_FAIL);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("操作延迟 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, Grobal2.CM_RUN, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 转向
        /// </summary>
        private unsafe void ClientTurn(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nCode = 120;
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientChangeDir(ProcessMsg.wIdent, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.wParam, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetTurnMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxTurnMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint);// '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage) // 如果超速则发送攻击失败信息
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sBunOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        SendSocket(null, M2Share.sSTATUS_FAIL);
                    }
                    else
                    {
                        if (dwDelayTime < M2Share.g_Config.dwDropOverSpeed)
                        {
                            SendSocket(null, M2Share.sSTATUS_GOOD);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 走路
        /// </summary>
        private unsafe void ClientWalk(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nCode = 121;
            uint dwDelayTime = 0;
            int nMsgCount = 0;
            if (ClientWalkXY(ProcessMsg.wIdent, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.boLateDelivery, ref dwDelayTime))
            {
                m_dwActionTick = HUtil32.GetTickCount();
                if (M2Share.g_Config.boStartMapEvent) // 开启地图事件触发
                {
                    if (this.m_btRaceServer == Grobal2.RC_PLAYOBJECT)
                    {
                        StartMapEventOfWalk(); // 走路事件触发
                    }
                }
                SendSocket(null, M2Share.sSTATUS_GOOD);
            }
            else
            {
                if (dwDelayTime == 0)
                {
                    SendSocket(null, M2Share.sSTATUS_FAIL);
                }
                else
                {
                    nMsgCount = GetWalkMsgCount();
                    if (nMsgCount >= M2Share.g_Config.nMaxWalkMsgCount)
                    {
                        m_nOverSpeedCount++;
                        if (m_nOverSpeedCount > M2Share.g_Config.nOverSpeedKickCount)
                        {
                            if (M2Share.g_Config.boKickOverSpeed)
                            {
                                this.SysMsg(GameMsgDef.g_sKickClientUserMsg, TMsgColor.c_Red, TMsgType.t_Hint);// '请勿使用非法软件！！！'
                                m_boEmergencyClose = true;
                                m_boPlayOffLine = false;
                            }
                            if (M2Share.g_Config.boViewHackMessage)
                            {
                                M2Share.MainOutMessage(string.Format(GameMsgDef.g_sWalkOverSpeed, this.m_sCharName, dwDelayTime, nMsgCount));
                            }
                        }
                        SendSocket(null, M2Share.sSTATUS_FAIL); // 如果超速则发送攻击失败信息
                        if (m_boTestSpeedMode)
                        {
                            this.SysMsg(string.Format("速度异常 Ident: {0} Time: {0}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                        }
                    }
                    else
                    {
                        if ((dwDelayTime > M2Share.g_Config.dwDropOverSpeed) && (M2Share.g_Config.btSpeedControlMode == 1) && m_boFilterAction)
                        {
                            SendSocket(null, M2Share.sSTATUS_FAIL);
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("速度异常 Ident: {0} Time: {0}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                        }
                        else
                        {
                            if (m_boTestSpeedMode)
                            {
                                this.SysMsg(string.Format("操作延迟 Ident: {0} Time: {1}", ProcessMsg.wIdent, dwDelayTime), TMsgColor.c_Red, TMsgType.t_Hint);
                            }
                            this.SendDelayMsg(this, ProcessMsg.wIdent, ProcessMsg.wParam, ProcessMsg.nParam1, ProcessMsg.nParam2, ProcessMsg.nParam3, "", dwDelayTime);
                            boResult = false;
                        }
                    }
                }
            }
        }

        /// <summary>
        /// 被攻击
        /// </summary>
        private void ServerStruck(TProcessMessage ProcessMsg, ref bool boResult)
        {
            int nCode = 0;
            if (ProcessMsg.wParam > 0)
            {
                nCode = 275;
                TBaseObject BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
                if (BaseObject != null)
                {
                    nCode = 288;
                    if (BaseObject == this)
                    {
                        nCode = 289;
                        TBaseObject TagBaseObject = M2Share.ActorsSystem.Get(ProcessMsg.nParam3);
                        if (TagBaseObject != null)
                        {
                            nCode = 291;
                            if (!TagBaseObject.m_boDeath)
                            {
                                nCode = 292;
                                if ((TagBaseObject.m_btRaceServer == Grobal2.RC_PLAYOBJECT) || (TagBaseObject.m_btRaceServer == Grobal2.RC_HEROOBJECT))
                                {
                                    nCode = 154;
                                    this.SetPKFlag(TagBaseObject); //英雄灰色
                                }
                                nCode = 155;
                                this.SetLastHiter(TagBaseObject);
                            }
                        }
                        if ((M2Share.g_CastleManager.IsCastleMember(this) != null) && (TagBaseObject != null))
                        {
                            TagBaseObject.bo2B0 = true;
                            TagBaseObject.m_dw2B4Tick = HUtil32.GetTickCount();
                        }
                        this.m_nHealthTick = 0;
                        this.m_nSpellTick = 0;
                        this.m_nPerHealth -= 1;
                        this.m_nPerSpell -= 1;
                        this.m_dwStruckTick = HUtil32.GetTickCount();
                    }
                }
                nCode = 276;
                BaseObject = M2Share.ActorsSystem.Get(ProcessMsg.BaseObject);
                if (BaseObject != null)
                {
                    if (((BaseObject == this) && (M2Share.g_Config.boDisableSelfStruck)) ||
                        ((BaseObject.m_btRaceServer == Grobal2.RC_PLAYOBJECT) && M2Share.g_Config.boDisableStruck))
                    {
                        nCode = 278;
                        BaseObject.SendRefMsg(Grobal2.RM_HEALTHSPELLCHANGED, 0, 0, 0, 0, "");// 人物受打击无弯腰动作
                    }
                    else
                    {
                        nCode = 279;
                        this.m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_STRUCK, ProcessMsg.BaseObject, BaseObject.m_WAbil.HP,
                            BaseObject.m_WAbil.MaxHP, ProcessMsg.wParam, 0);
                        nCode = 280;
                        TMessageBodyWL MessageBodyWL = new TMessageBodyWL();
                        THealth Health = new THealth()
                        {
                            HP = BaseObject.m_WAbil.HP,
                            MaxHP = BaseObject.m_WAbil.MaxHP
                        };
                        MessageBodyWL.lParam1 = BaseObject.GetFeature(this);
                        MessageBodyWL.lParam2 = BaseObject.m_nCharStatus;
                        MessageBodyWL.lParam3 = BaseObject.GetFeatureJob();
                        MessageBodyWL.lTag1 = ProcessMsg.nParam3;
                        if (ProcessMsg.wIdent == Grobal2.RM_STRUCK_MAG)
                        {
                            MessageBodyWL.lTag2 = 1;
                        }
                        else
                        {
                            MessageBodyWL.lTag2 = 0;
                        }
                        SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(MessageBodyWL) + "/" + EncryptUnit.EncodeBuffer(Health));
                    }
                }
            }
        }
    }
}